<?php

declare(strict_types=1);

namespace App\Command;

use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Psr\Container\ContainerInterface;
use App\Service\CommodityService\SupplierCommodityXingyunPullLogService;

/**
 * @Command
 */
class SupplierCommodityXyxbV2PullTask extends HyperfCommand
{
    const TIME_WAIT = 10;
    /**
     * @var ContainerInterface
     */
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;

        parent::__construct('SupplierCommodityXyxbV2PullTask');
    }

    public function configure()
    {
        parent::configure();
        $this->setDescription('拉取行云中小B供应商商品');
    }

    public function handle()
    {
        $args = $this->input->getArguments();
        $SupplierID = $args['SupplierID'] ?? 0 ;
        //单个供应商
        if( $SupplierID > 0 ) {
            SupplierCommodityXingyunPullLogService::instance()->runTask($SupplierID);
        } else {
            while ( true )
            {
                SupplierCommodityXingyunPullLogService::instance()->runTask('shopxingyunxbv2');
                sleep(self::TIME_WAIT);
            }
        }
        $this->line(json_encode($res,JSON_UNESCAPED_UNICODE), 'info');
    }
}
